//
//  YSGWesternSearchViewModel.swift
//  EyeVisionForPatients
//
//  Created by liuyutian on 2022/7/1.
//  Copyright © 2022 QDSG. All rights reserved.
//

import UIKit
import HandyJSON

struct YSGWesternSearchModel: HandyJSON{
    
    var id : Int = 0
    var name : String = "" //药品名称
    var currencyName : String = "" //通用名称
    var manufacturer : String  = "" //生产厂家
    var drugSpecification : String = "" //药品规格
}

class YSGWesternSearchViewModel: NSObject {
    
    var searchList: [YSGWesternSearchModel] = []
    
    func getWesternSearchList(page : Int,keyWords : String,finished: @escaping () -> Void) {
        let params = ["keyWords": keyWords,"current": page] as [String : Any]
        HttpTool.shared.request(target: ApiManager.getWesternSearchList(paras: params), success: { (json, code) in
            YSGLog(json)
            if let models = JSONDeserializer<YSGWesternSearchModel>.deserializeModelArrayFrom(json: json["data"]["records"].description) as? [YSGWesternSearchModel] {
                if page == 0 {
                    self.searchList = models
                }else{
                    self.searchList.append(contentsOf: models)
                }
                
            } else {
                
            }
            finished()
        }) { error in
            YSGLog(error)
            finished()
        }
    }
}
